import Notfont from "../components/Notfont"; //404页面
import { start, done, configure } from "nprogress"; //加载条库
import "nprogress/nprogress.css";
configure({
    trickleSpeed: 20, //加载条速度
    showSpinner: false, //小圆圈加载
})

function delay(duration) { //异步辅助函数

    return new Promise((resole) => {
        setTimeout(() => {
            resole();
        }, duration)
    })
};

function getRouteComponent(RouteComponent) { //辅助函数用来动态获取路由页面同时设置加载条，传入一个回调函数，用来让路由更好筛选
    return async() => {
        if (process.env.NODE_ENV === 'development') { //是不是开发环境呀
            delay(2000); //停两秒
        }
        start(); //加载条开始动起来
        const comp = await RouteComponent(); //获取异步路由页面
        done(); //加载条结束
        return comp; //返回加载的异步模块
    }
}
export default [{
        name: "Home",
        path: '/',
        component: getRouteComponent(() =>
            /* 首页 home */
            import ('@/views/Home')),

        meta: { title: '首页', }
    },
    {
        name: "Blog",
        path: '/blog',
        component: getRouteComponent(() => /* 文章 Blog" */
            import ("@/views/Blog")),
        meta: { title: '文章', }
    },
    {
        name: "CategoryBlog",
        path: '/blog/cate/:categoryId',
        component: getRouteComponent(() => /* 文章 Blog" */
            import ("@/views/Blog")),
        meta: { title: '文章', }
    },
    {
        name: "BlogDetail",
        path: '/blog/:id',
        component: getRouteComponent(() => /* 文章 Blog/Detail" */
            import ("@/views/Blog/Detail")),
        meta: { title: '文章详情', }
    },
    {
        name: "About",
        path: '/about',
        component: getRouteComponent(() => /* 关于我 About" */
            import ("@/views/About")),
        meta: { title: '关于我', }
    },
    {
        name: "Project",
        path: '/project',
        component: getRouteComponent(() => /* 项目与工程 Project" */
            import ("@/views/Project")),
        meta: { title: '项目&工程', }
    },
    {
        name: "Message",
        path: '/message',
        component: getRouteComponent(() => /* 留言板 Message" */
            import ("@/views/Message")),
        meta: { title: '留言板', }
    },
    { name: "Notfont", path: '/*', component: Notfont, },


];